package com.example.application1.Adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.application1.Entity.NewslistDTOXXXX;
import com.example.application1.R;

import java.util.List;

public class festivalAdapter extends RecyclerView.Adapter<festivalAdapter.festivalHolder> {

    private Context context;
    private List<NewslistDTOXXXX> festivalList;

    public festivalAdapter(Context context,List<NewslistDTOXXXX> festivalList) {
        this.context=context;
        this.festivalList=festivalList;
    }

    @NonNull
    @Override
    public festivalHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new festivalHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.festival_item,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull festivalHolder holder, int position) {
            holder.festival1.setText(festivalList.get(position).getTip());
    }

    @Override
    public int getItemCount() {
        return festivalList==null?0:festivalList.size();
    }

    public  void refresh(List<NewslistDTOXXXX> festivalList){
//      对适配器刷新
        this.festivalList=festivalList;
        notifyDataSetChanged();
        Log.d("lcj","notifyDataSetChanged");
    }

    public class festivalHolder extends RecyclerView.ViewHolder{
        TextView festival1;
        public festivalHolder(@NonNull View itemView) {
            super(itemView);
            festival1=itemView.findViewById(R.id.festival1);
        }
    }
}
